﻿using UnityEngine;
using System.Collections;
using MessageSystem;
using BehaviorSystem;
public class PlayerMoveComponent : MonoBehaviour
{
    MessageTerminal messageTerminal;
    CharacterController characterController;
    
    public Vector3 targetPos=Vector3.zero;

    public float Speed=0.02f;

    public bool IsCanMove = true;

    void Start()
    {
        messageTerminal = GetComponent<MessageTerminal>();
        messageTerminal.RegisterMessage("Click", OnMessage);
        //characterController = GetComponentInChildren<CharacterController>();
        
    }


    void OnMessage(IMessageArgs args)
    {
        ClickArgs data = (ClickArgs)args;
        if (data!=null)
        {
            Vector3 worldPos=TransferUtils.ScreenPoitToWorldPos(data.ScreenPos, "BattleTerrain");
            if (worldPos!=Vector3.zero)
            {
                targetPos = worldPos;
                targetPos.y = transform.position.y;
            }
            else
            {
                targetPos = transform.position;
            }


            //characterController.Move(worldPos - transform.position);
            
            //transform.position= worldPos;
        }
    }

    private void Update()
    {
        

    }
}
